package com.lecture.essence.demo01;

import cn.hutool.core.util.ArrayUtil;

public class FXNewsProvider {

    private IFXNewsListener newsListener;

    private IFXNewsPersister newsPersister;

    public FXNewsProvider() {
        newsListener = new DowJonesNewsListener();
        newsPersister = new DowJonesNewsPersister();
    }

    public void getAndPersistNews() {
        String[] newsIds = newsListener.getAvailableNewsIds();
        if (ArrayUtil.isEmpty(newsIds)) {
            return;
        }
        for (String newsId : newsIds) {
            FXNewsBean newsBean = newsListener.getNewsByPK(newsId);
            newsPersister.persistNews(newsBean);
            newsListener.postProcessIfNecessary(newsId);

        }
    }

}
